﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Evaluation;
using Xunit;
using System.Diagnostics;
using Microsoft.Build.Construction;
using System.IO;

namespace Genuilder.Tests
{
	public static class Extensions
	{
		[DebuggerHidden]
		public static void AssertHas(this IEnumerable<ProjectImportElement> imports, string project)
		{
			Assert.True(imports.Any(i => FileEqual(i.Project, project)), "no import of " + project + " was found");
		}
		[DebuggerHidden]
		public static void AssertHasNot(this IEnumerable<ProjectImportElement> imports, string project)
		{
			Assert.False(imports.Any(i => FileEqual(i.Project, project)), "import " + project + " was found");
		}


		public static void AssertBuild(this BuildResult buildResult)
		{
			Assert.True(buildResult.Success, "Some errors appeared during the build");
		}
		public static void OpenDirectory(this BuildResult buildResult)
		{
			Process.Start(new ProcessStartInfo(Path.Combine(new FileInfo(buildResult.ProjectFile).Directory.FullName, "obj/Debug"))
			{
				WindowStyle = ProcessWindowStyle.Maximized,
				
			});
		}

		private static bool FileEqual(string f1, string f2)
		{
			return new FileInfo(f1).FullName == new FileInfo(f2).FullName;
		}
	}
}
